package com.yuke.cloud.service.omc.controller.frontend;


import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.omc.dto.OrderProdDto;
import com.yuke.cloud.service.omc.service.OdsExcelImportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ods/excel")
@Slf4j
public class OdsExcelImportController extends BaseController {

    @Autowired
    private OdsExcelImportService odsExcelImportService;

    @PostMapping("/import")
    public  Wrapper<String> getImprotOrder(@RequestBody List<OrderProdDto> orderProdDtos){
       Map<String, Integer> map = new HashMap<>();
        if (orderProdDtos != null && orderProdDtos.size()>0){
            map = odsExcelImportService.doIt(orderProdDtos);
        }
        String str = "导入订单结果：订单成功导入"+map.get("orderSuccess")+"条。";
        return WrapMapper.ok(str);
    }

    @PostMapping("/importCheck")
    public Wrapper<String> checkTable(@RequestBody List<OrderProdDto> orderProdDtos){
        String str="无识别消息！";
        if (orderProdDtos != null && orderProdDtos.size()>0){
           str = odsExcelImportService.checkTable(orderProdDtos);
        }
        return WrapMapper.ok(str);
    }

    @PostMapping("/checkShopName")
    public Wrapper<String> checkShopName(@RequestBody List<OrderProdDto> orderProdDtos){
        String str="无识别消息！";
        if (orderProdDtos != null && orderProdDtos.size()>0){
            str = odsExcelImportService.checkShopName(orderProdDtos);
        }
        return WrapMapper.ok(str);
    }

    @PostMapping("/checkSpecName")
    public Wrapper<String> checkSpecName(@RequestBody List<OrderProdDto> orderProdDtos){
        String str="无识别消息！";
        if (orderProdDtos != null && orderProdDtos.size()>0){
            str = odsExcelImportService.checkSpecName(orderProdDtos);
        }
        return WrapMapper.ok(str);
    }
}
